﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LIMS.Web
{
    public partial class AdmAdminManage : System.Web.UI.Page
    {
         
        protected void Page_Load(object sender, EventArgs e)
        {
            mesEmptyError.InnerText = "";
            if (!IsPostBack)
            {
                AspNetPager1.RecordCount = BLL.AdminManager.GetAdmins().Count();
                //rpAdmin.DataSource = BLL.CommonPager<Model.Admins>.GetTSourceByPager(BLL.AdminManager.GetAdmins(), AspNetPager1.PageSize, 1);
                rpAdmin.DataSource = BLL.AdminManager.GetAdmins();
                rpAdmin.DataBind();
            }
        }

        protected void rpAdmin_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {

        }

        protected void btnFlushAdmin_Click(object sender, EventArgs e)
        {
            rpAdmin.DataSource = BLL.AdminManager.GetAdmins();
            rpAdmin.DataBind();
        }

        protected void btnFind_Click(object sender, EventArgs e)
        {
            var Demo = BLL.AdminManager.GetAdminByName(txtAdminName.Value.Trim());
            rpAdmin.DataSource = Demo;
            rpAdmin.DataBind();
        }

        protected void btnAddAdmin_Click(object sender, EventArgs e)
        {
            Model.Admins admin = new Model.Admins()
            {
                adminID = txtAdminNo.Value.Trim(),
                adminName = txtAdminName.Value.Trim(),
                adminPwd = txtAdminPwd.Text.Trim()
            };
            if (BLL.AdminManager.CheckAdminID(admin.adminID))
            {
                BLL.AdminManager.AddAdmin(admin);
            }
            rpAdmin.DataSource = BLL.CommonPager<Model.Admins>.GetTSourceByPager(BLL.AdminManager.GetAdmins(), AspNetPager1.PageSize, 1);
            rpAdmin.DataBind();
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rpAdmin.DataSource = BLL.CommonPager<Model.Admins>.GetTSourceByPager(BLL.AdminManager.GetAdmins(), AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
            rpAdmin.DataBind();
        }
        protected void btnRemoveAdmin_Click(object sender, EventArgs e)
        {

        }

        protected void btnCheckID_Click(object sender, EventArgs e)
        {
           
            if (!BLL.AdminManager.CheckAdminID(txtAdminNo.Value.Trim()))
            {
                mesEmptyError.InnerText = "该ID已经被注册！";
            }
            else
            {
                mesEmptyError.InnerText = "该ID可以使用！";
            }
        }
    }
}